package com.nft.service.school.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nft.service.school.entity.UserBookEntity;
import com.nft.service.school.resp.BookResp;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
@DS("master")
public interface UserBooksMapper extends BaseMapper<UserBookEntity> {
    @Select("select b.id, b.title, b.content, b.grade, b.subject, b.dispart, b.jxkey, "+
            "b.create_time as createTime, a.create_time as sjTime, a.id as userbookId " +
            "from user_books a left join nd_teaching_tasks b on b.id=a.task_id where a.user_id=#{userId}")
    public IPage<BookResp> getBookInfoPageByUserId(Page page, @Param("userId")Long userId);

    @Select("select b.id, b.title, b.content, b.grade, b.subject, b.dispart, b.jxkey, "+
            "b.create_time as createTime, a.create_time as sjTime, a.id as userbookId " +
            "from user_books a left join nd_teaching_tasks b on b.id=a.task_id where a.user_id=#{userId}")
    public List<BookResp> getBookInfoListByUserId(@Param("userId")Long userId);

    @Select("select b.id, b.title, b.content, b.grade, b.subject, b.dispart, b.create_time as createTime, a.create_time as sjTime " +
            "from user_books a left join nd_teaching_tasks b on b.id=a.task_id where a.user_id=#{userId} and b.id=#{taskId}")
    public BookResp getBookInfosByUserIdAndId(@Param("userId")Long userId, @Param("taskId")Long taskId);
}
